package com.itheima.service.db.imp;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.db.UserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserServiceImp implements UserService {
    @Autowired//注入userMapper
    private UserMapper userMapper;
    @Override//实现用户保存
    public Long save(User user) {
        user.setPassword(SecureUtil.md5(user.getPassword()));
        userMapper.insert(user);
        return user.getId();
    }

    @Override//实现通过手机号查询用户
    public User findByPhone(String phone) {
        QueryWrapper<User> qw=new QueryWrapper<>();
        qw.eq("phone",phone);
        User user = userMapper.selectOne(qw);
        return user;
    }

    @Override//修改手机号根据userid
    public void updatePhoneById(User user) {
        userMapper.updateById(user);
    }
}
